<template>
  <div>
    <Header_h />
    <div class="sq_box_content">
      <bannerInfo :info="info" />
    </div>
    <div class="new_box_bgcolor">
      <div class="new_box">
        <div class="container">
          <div class="s_flex s_align_items_start">
            <leftMenu :menu="menu" :check="active" @checkItem="checkItem" />
            <div style="width: 100%">
              <section class="core_content_left core_content">
                <div
                  class="
                    item_list
                    s_flex s_flex_comlou s_justify_content_between
                  "
                  v-for="(news, index) in list.list"
                  :key="index"
                  @click="goNews(news.id)"
                  @mouseenter="enter(index)"
                  @mouseleave="leave(index)"
                  :class="check == index ? 'li_active' : ''"
                >
                  <div class="item_list_img">
                    <div class="img_wap">
                      <img class="item_list_img" :src="news.tpic" alt="" />
                    </div>
                  </div>
                  <div class="right_info">
                    <div
                      class="
                        s_flex s_align_items_center s_justify_content_between
                      "
                    >
                      <p class="sq_content sq_content_color">
                        {{ news.create_time }}
                      </p>
                      <div
                        v-if="news.active_status == 1"
                        class="sq_sign sq_content ft_weight_400"
                      >
                        报名中
                      </div>
                      <div v-else class="sq_end sq_content">已结束</div>
                    </div>
                    <h3
                      class="
                        sq_title3
                        line_h_30
                        sq_tilte_color
                        content_spacing
                        ft_weight_800
                      "
                    >
                      {{ news.title }}
                    </h3>
                    <div class="sq_content sq_content_color">
                      <p
                        class="ft_weight_400 line_h_26 words-hidden-3"
                        v-html="news.content"
                      ></p>
                    </div>
                  </div>
                </div>
              </section>
            </div>
          </div>
          <div class="pagination">
            <el-pagination
              background
              small
              @current-change="handleCurrentChange"
              :current-page="list.page"
              :page-size="list.size"
              layout="total, prev, pager, next, jumper"
              :total="parseInt(list.count)"
              align="left"
            ></el-pagination>
          </div>
        </div>
      </div>
    </div>
    <Footer />
    <rightMenu @moveTo="moveTo" />
  </div>
</template>

<script>
import Header_h from "@/components/Header_h";
import Footer from "@/components/Footer";
import bannerInfo from "@/components/web/bannerInfo";
import leftMenu from "@/components/web/leftMenu";
import { activityList } from "@/api/web";
import rightMenu from "@/components/web/rightMenu";

export default {
  components: {
    Header_h,
    Footer,
    bannerInfo,
    leftMenu,
    rightMenu,
  },
  data() {
    return {
      list: [],
      banner: [],
      info: {
        title: "培训活动",
        content: "最新的活动资讯，等你来报名",
        img: require("@/assets/web/banner.png"),
      },
      check: -1,
      active: 1,
      menu: [
        {
          name: "中心介绍",
          path: "/web/services/introduce",
        },
        // {
        //   name: "顺企动态",
        //   path: "/web/services/dynamic",
        // },
        {
          name: "培训活动",
          path: "/web/services/central",
        },
        {
          name: "新闻资讯",
          path: "/web/news",
        },
      ],
    };
  },
  mounted() {
    this.getList();
    this.getBanner();
  },
  methods: {
    //点击第几页
    async handleCurrentChange(currentPage) {
      try {
        this.getList(currentPage);
      } catch (e) {
        this.$message.error(e.message);
      }
    },
    moveTo() {
      window.scrollTo(0, 0);
    },
    async getBanner() {
      // try {
      //   this.banner = await bannerList({ from: 1 });
      // } catch (error) {
      //   this.$message.error(error.message);
      // }
    },
    async getList(page = 1) {
      try {
        this.list = await activityList({
          page_size: 5,
          page,
        });
        // this.list={...this.list,count:12}
      } catch (error) {
        this.$message.error(error.message);
      }
    },
    goNews(id) {
      this.$router.push({ path: "/web/central/details", query: { id: id } });
    },
    webUrl(url) {
      window.open(url);
    },
    enter(index) {
      this.check = index;
    },
    leave() {
      this.check = -1;
    },
    checkItem(index) {
      this.active = index;
    },
  },
};
</script>

<style lang="less" scoped>
/* core_content */
.new_box {
  margin-top: -4%;
  position: relative;
  z-index: 1;
  margin-bottom: 60px;
}
.core_content .item_list_img {
  width: 240px;
  object-fit: cover;
  overflow: hidden;
  .img_wap {
    padding-bottom: 56%;
    width: 100%;
    position: relative;
    img {
      width: 100%;
      transition: all 0.5s ease;
      &:hover {
        transform: scale(1.1);
      }
    }
  }
}

.li_active {
  width: 100%;
  background: #ffffff;
  box-shadow: 0 0 16px rgba(24, 76, 171, 0.16);
  border: none;
}

.right_info {
  width: 70%;
}

.core_content .item_list {
  border-bottom: 1px solid #eee;
  padding: 23px 15px;
  width: 100%;
  margin-bottom: 30px;
  background: #ffffff;
  border: 1px solid #ced4ea;
  cursor: pointer;
  transition: all 0.2s ease;
}

.core_content .item_list:last-child {
  margin-bottom: 0;
}

.content_spacing {
  margin: 10px auto;
}
.core_content_left {
  width: 80%;
  margin-left: 250px;
  background-color: #fff;
  height: 100%;
}
.core_content_right {
  width: 25%;
  background-color: #fff;
}
.content_right_spacing {
  margin: 10px 0;
}
.list_right {
  border-top: 1px solid #eee;
  padding: 10px 0;
  margin: 0 10px;
}
.right_title {
  margin: 0 10px;
  padding: 10px 0;
}

/* core_content */

@media (max-width: 750px) {
  .core_content .item_list_img {
    width: 100%;
    height: 127px;
    margin-right: 0;
    margin-bottom: 20px;
  }
  .core_content_left {
    width: 100%;
    background-color: #fff;
    height: 100%;
  }
  .core_content {
    padding: 20px 0;
  }
}
.pagination {
  width: 90%;
  margin: 40px auto 0;
}
</style>

